package com.yunhe.sms.dao.activite.impl;

import com.yunhe.commens.dao.impl.BaseDaoImpl;
import com.yunhe.commens.dto.Pagedao;
import com.yunhe.sms.dao.activite.VoteItemDao;
import com.yunhe.sms.entity.activity.Voteitem;

import java.util.List;

/**
 * @author LeiPeifeng
 * @version V1.0
 * @date 2017/10/31 0031 14:33
 * @Description: 实现VoteItem接口
 */
public class VoteItemDaoImpl extends BaseDaoImpl<Voteitem> implements VoteItemDao {
    @Override
    public void add(Voteitem voteItem) {
        String sql=" insert into vote_item(vote_id,name,img,details,votes,sort_no,status,deleted,creat_time) values(?,?,?,?,?,?,?,0,now() ) ";
        super.cut ( sql,voteItem.getVoteId (),voteItem.getName (),voteItem.getImg (),voteItem.getDetails (),voteItem.getVotes (),voteItem.getSortNo (),voteItem.getStatus ());
    }

    @Override
    public void deleted(Long id) {
        String sql=" update vote_item set deleted=1 where id=? ";
        super.cut ( sql,id );
    }

    @Override
    public void update(Voteitem voteItem) {
        String sql=" update vote_item set vote_id=?,name=?,img=?,details=?,votes=?,sort_no=?,status=? where id=? ";
        super.cut ( sql,voteItem.getVoteId (),voteItem.getName (),voteItem.getImg (),voteItem.getDetails (),voteItem.getVotes (),voteItem.getSortNo (),voteItem.getStatus (),voteItem.getId () );
    }

    @Override
    public void count(Long id) {
        String sql=" update vote_item set votes=(votes+1) where id=? ";
        super.cut ( sql,id );
    }

    @Override
    public Voteitem findId(Long id) {
        String sql=" select id,vote_id voteId,name,img,details,votes,sort_no sortNo,status from vote_item where deleted=0 and  id=? ";
        return super.quaryOne ( sql,id );
    }

    @Override
    public List<Voteitem> find(Long voteId) {
        String sql=" select id,vote_id voteId,name,img,details,votes,sort_no sortNo,status from vote_item where deleted=0 and status=1 and vote_id=? ";
        return super.quaryList ( sql,voteId );
    }

    @Override
    public Pagedao<Voteitem> page(int offset, int limit,Long voteId) {
        String listsql=" select id,vote_id voteId,name,img,details,votes,sort_no sortNo,status from vote_item where deleted=0 and vote_id="+voteId ;
        String countsql=" select count(*) from vote_item where deleted=0 and vote_id="+voteId;
        return super.quaryPage ( listsql,countsql,offset,limit );
    }
}
